<!--
 * 退货记录管理页面
 * 显示所有退货记录，包括退货编号、商品信息、客户信息、退货时间等
 -->
<template>
    <view-grid ref="grid"
               :columns="columns"
               :detail="detail"
               :details="details"
               :editFormFields="editFormFields"
               :editFormOptions="editFormOptions"
               :searchFormFields="searchFormFields"
               :searchFormOptions="searchFormOptions"
               :table="table"
               :extend="extend"
               :onInit="onInit"
               :onInited="onInited"
               :searchBefore="searchBefore"
               :searchAfter="searchAfter"
               :addBefore="addBefore"
               :updateBefore="updateBefore"
               :rowClick="rowClick"
               :modelOpenBefore="modelOpenBefore"
               :modelOpenAfter="modelOpenAfter">
        <!-- 自定义头部按钮 -->
        <template #gridHeader>
            <el-button type="primary" @click="refreshData">
                <i class="el-icon-refresh"></i> 刷新
            </el-button>
            <el-button type="success" @click="exportData">
                <i class="el-icon-download"></i> 导出
            </el-button>
        </template>
    </view-grid>
</template>

<script setup lang="jsx">
    import viewOptions from './ReturnOrder/options.js'
    import { ref, reactive, getCurrentInstance } from "vue";
    import { ElMessage } from 'element-plus';
    
    const grid = ref(null);
    const { proxy } = getCurrentInstance()
    
    const { table, editFormFields, editFormOptions, searchFormFields, searchFormOptions, columns, detail, details } = reactive(viewOptions())
    
    // extend 配置（页面扩展功能）
    const extend = reactive({
        // 可以在这里添加自定义扩展功能
    })
    
    let gridRef;
    
    const onInit = async ($vm) => {
        gridRef = $vm;
    }
    
    const onInited = async () => {
    }
    
    const searchBefore = async (param) => {
        // 查询前处理
        return true;
    }
    
    const searchAfter = async (rows, result) => {
        // 查询后处理
        return true;
    }
    
    const addBefore = async (formData) => {
        // 新增前验证
        ElMessage.warning('退货记录由订单退货自动生成，无需手动添加');
        return false; // 阻止手动添加
    }
    
    const updateBefore = async (formData) => {
        // 更新前验证
        return true;
    }
    
    const rowClick = ({ row, column, event }) => {
        // 行点击事件
    }
    
    const modelOpenBefore = async (row) => {
        // 弹窗打开前
        return true;
    }
    
    const modelOpenAfter = (row) => {
        // 弹窗打开后
    }
    
    // 刷新数据
    const refreshData = () => {
        if (gridRef && gridRef.search) {
            gridRef.search();
            ElMessage.success('数据已刷新');
        }
    }
    
    // 导出数据
    const exportData = () => {
        if (gridRef && gridRef.export) {
            gridRef.export();
        } else {
            ElMessage.info('导出功能开发中...');
        }
    }
    
    defineExpose({})
</script>

<style lang="less" scoped>
</style>

